<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.*" %>
<%@ page import="cn.ekgc.web166.entity.Student" %>
<%@ page import="cn.ekgc.web166.commons.DateUtils" %>
<%@ page import="cn.ekgc.web166.dao.StudentDao" %>
<%@ page import="cn.ekgc.web166.dao.StudentDaoImpl" %><%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2019/6/11 0011
  Time: 17:55
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%

    request.setCharacterEncoding("utf-8");
    String name = request.getParameter("name");
    String gender = request.getParameter("gender");
    String bornday = request.getParameter("bornday");

    Student student = new Student(name,gender, DateUtils.getDate(bornday,"yyyy-MM-dd'T'HH:mm"));
    System.out.println(student);
    StudentDao dao = new StudentDaoImpl();
    dao.save(student);

    response.sendRedirect("show.jsp?id="+student.getId());

   /* String sql = "insert into xueyuan2(name,gender,bornday)value('"+name+"','"+gender+"','"+bornday+"')";
    Class.forName("com.mysql.jdbc.Driver");
    String url = "jdbc:mysql://localhost:3306/myschool2";
    String user = "root";
    String pwd = "123456";
    Connection conn = DriverManager.getConnection(url,user,pwd);
    Statement st = conn.createStatement();
    st.execute(sql);
    sql="select LAST_INSERT_ID() as id";
    ResultSet rs = st.executeQuery(sql);
    int id = 0;
    if(rs.next()){
        rs.getInt("id");//此id为sql中as id 的id，如果你没有as id 那么这里就填数字1
    }

    st.close();
    conn.close();
    response.sendRedirect("show.jsp?id="+id);
*/

%>

